<template>
    <div>
                <el-table
                        :data="tableData"
                        border
                        style="width:100%">
                    <el-table-column
                            type="index"
                            label="#"
                            width="180">
                    </el-table-column>
                    <el-table-column
                            prop="label"
                            label="子类名称"
                            width="180">
                    </el-table-column>
                    <el-table-column
                            label="层次">
                        <el-tag type="success">二级分类</el-tag>
                    </el-table-column>
                    <el-table-column
                            fixed="right"
                            label="操作"
                            width="100">
                        <template slot-scope="scope">
                            <el-button type="text" size="small" @click="edit(scope)">编辑</el-button>
                            <el-button @click="delType(scope)" type="text" size="small" style="color: red">删除</el-button>
                        </template>
                    </el-table-column>
                </el-table>
    </div>
</template>

<script>
    import {sendwithpost} from "../../../../network/profile";
    import {eventBus} from "../../../../common/util";

    export default {
        name: "GoodsTypeItem",
        props: {
          tableData: {
              type: Array,
              default: []
          }
        },
        data() {
            return {

            }
        },
        methods: {
            delType(scope) {
                sendwithpost({
                    url: '/deltype',
                    data: scope.row
                }).then(res=> {
                    if (res.data.res_code == 2) {
                        this.$store.dispatch('getGoodsType');
                        this.$message({
                            showClose: true,
                            message: '删除成功',
                            type: 'success'
                        })
                    } else {
                        this.$message({
                            showClose: true,
                            message: res.data.message,
                            type: 'success'
                        })
                    }
                })
            },
            edit(scope) {
                eventBus.$emit('editType', scope)
            }
        }
    }
</script>

<style scoped>

</style>